package com.rjgc.title.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.rjgc.title.mapper.PracticeMapper;
import com.rjgc.title.model.entity.user.Practice;
import com.rjgc.title.service.PracticeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 职业资格 服务实现类
 * </p>
 *
 * @author 卓抱抱
 * @since 2022-04-25
 */
@Service
public class PracticeServiceImpl extends ServiceImpl<PracticeMapper, Practice> implements PracticeService {

    @Autowired
    private PracticeMapper practiceMapper;

    @Override
    public Practice getByUserId(String userId) {
        QueryWrapper<Practice> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("userId", userId);

        Practice practices = practiceMapper.selectOne(queryWrapper);
        return practices;
    }

    /**
     * 保存 更新
     * @param practice
     */
    @Override
    public void saveSkillLevel(Practice practice) {
        if (practice.getId() != null) {
            // 更新
            practiceMapper.updateById(practice);
        } else {
            // 保存
            practiceMapper.insert(practice);
        }
    }
}
